﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace RenShiKaoQin.Account
{
    public partial class ZNGL_Form : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            tbStartDate.Attributes["readonly"] = "readonly";
            tbEndDate.Attributes["readonly"] = "readonly";
            sqlApplication.SelectParameters["UserID"] = new Parameter("UserID", TypeCode.String, Page.User.Identity.Name);
        }

        protected void gvPeople_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "SelectPeople")
            {
                int rowIndex = int.Parse(e.CommandArgument.ToString());
                lbName.Text = gvPeople.Rows[rowIndex].Cells[0].Text;
                lbDept.Text = gvPeople.Rows[rowIndex].Cells[1].Text;
                DataView dv = (DataView)sqlPeople.Select(DataSourceSelectArguments.Empty);
                hfID.Value = dv.Table.Rows[rowIndex]["FEmployeeID"].ToString();
                hfDept.Value = dv.Table.Rows[rowIndex]["FDeptCode"].ToString();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (lbName.Text == "" || lbDept.Text == "" || tbStartDate.Text == "" || tbEndDate.Text == null)
            {
                return;
            }
            using (hrdbEntities ent = new hrdbEntities())
            {
                TKQRequestRecord rec = TKQRequestRecord.CreateTKQRequestRecord(hfID.Value, DateTime.Parse(tbStartDate.Text), DateTime.Parse(tbEndDate.Text), ddlType.SelectedItem.Value, true, true, 0, true, hfDept.Value, false);
                rec.CheckDate = DateTime.Now;
                rec.CheckerID = Page.User.Identity.Name;
                rec.ExamDate = DateTime.Now;
                rec.ExamerID = Page.User.Identity.Name;
                rec.Memo = tbMemo.Text;
                ent.TKQRequestRecords.AddObject(rec);
                ent.SaveChanges();
            }
        }
    }
}